<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/1/4 0004
 * Time: 17:47
 */
namespace app\wap\controller;
use think\Db;
use think\Controller;
class Index extends Base
{

           public function add_bj() { 
        $where["name"] = input('post.name');
        $where["phone"] = input('post.phone');
        $where["content"] = input('post.content');
        $where["create_time"] = time();
        $where["is_del"] = "0";
        $result = Db::name('bj')->insert($where);
        if ($result !== false) {
            return json(['code' => 1, 'msg' => '操作成功']);
        } else {
            return json(['code' => 0, 'msg' => '操作失败']);
        }
    }
    

    public function index()
    {
        //广告
        $data_banner = Db::name('banner')->where('is_del= 0 and is_show =1 and sign="mobile" and class_id = 65')->select();
        $this->assign('data_banner', $data_banner);
        //客照时间
//        $where = 'is_del=0 and is_show=1 and  sign="mobile"';
//        $sql_1 = 'SELECT FROM_UNIXTIME(ps_time,\'%Y\') nian  FROM `dh_works` where ' . $where . '  GROUP BY nian ORDER BY nian DESC  LIMIT 1';
//        $max_year = Db::name('works')->query($sql_1);
//拍摄基地
        $data_psjd = Db::name('psjd')->
        where('is_del= 0 and is_show =1 and sign="mobile"')->
        order('sort asc')->select();
        $this->assign('data_psjd', $data_psjd);
// 最新主题
        $data_worknews = Db::name('worknews')->
        where('is_del= 0 and is_show =1 and sign="mobile"')->
        order('sort asc')->limit(4)->select();
        $this->assign('data_worknews', $data_worknews);
//
        $data_works = Db::name('works')->
        where('is_del= 0 and is_show =1 and sign="mobile"')->
        order('sort asc')->limit(6)->select();
        $this->assign('data_works', $data_works);
//        $max_year = $max_year[0]['nian'];
//        $this->assign('max_year', $max_year);
//        $this->assign('month_data', getMonth(''));
//        $sql_3 = 'SELECT FROM_UNIXTIME(ps_time,\'%m\') yue  FROM `dh_works` where ' . $where . ' and FROM_UNIXTIME(ps_time,\'%Y\') =' . $max_year . '  GROUP BY yue ORDER BY yue DESC  LIMIT 1';
//        $max_yue = Db::name('works')->query($sql_3);
//        $max_yue = $max_yue[0]['yue'];//最大的月份
        //vcr
//        $data_vcr = Db::name('vcr')->where('is_show=1 and is_del =0 and sign="mobile"  and is_recom=1')->order('sort desc,id desc')->limit(1)->find();
//        $this->assign('data_vcr',$data_vcr);
//        $this->assign('max_yue', intval($max_yue));
//        $time = $max_year . '-' . $max_yue;
//        $max_time = strtotime($time);
        //每周客照
//        $where = "is_recom=1 and is_del=0 and is_show =1 and sign='mobile' and ((FROM_UNIXTIME(ps_time,'%Y-%m') ='$max_year-$max_yue') or ps_time <=$max_time) and FROM_UNIXTIME(ps_time,'%Y') =$max_year";
//        $data_kz = Db::name('works')->where($where)->order('ps_time desc,id desc')->limit(20)->select();
//        $this->assign('data_kz', $data_kz);
        //栏目seo
        
        $header_logo ='<img src="/static/wap/img/yt-logo.png" alt="">';
        $this->assign('header_logo', $header_logo);
        $this->assign('data_seo', getColumnseo(1));
        return $this->fetch();
    }
        public function about(){
        $header_logo ='关于粉黛墨';
        $this->assign('header_logo', $header_logo);
            return $this->fetch();
        }
        //拍摄流程
         public function pslc(){
             $header_logo ='拍摄流程';
            $this->assign('header_logo', $header_logo);
            return $this->fetch();
        }
        public function addconsult(){
        $data=[
            'lf_num'=>input('post.lf_num'),
            'mobile'=>input('post.phone'),
            'xc_num'=>input('post.xc_num'),
            'xk_num'=>input('post.xk_num'),
            'create_time'=>time(),
            'sign'=>'mobile'
        ];
        if(isset($_POST['ps_style'] ) && $_POST['ps_style'] !==''){
            $data['ps_style'] = implode(',',$_POST['ps_style']);
        }
        $result = Db::name('consult')->insert($data);

        if($result){
            $content = '客户号码:'.$data['mobile'].',请您及时联系。[来自移动端]';
            send_mail('您的网站有新的客户信息',$content);
            return json(['code'=>1,'msg'=>'操作成功']);
        }else{
            return json(['code'=>0,'msg'=>'操作失败']);
        }
    }





}